package com.genshang.restaurant.util;

import java.util.Random;

public class RandomUtil {

    public static Random random = new Random();

    /**
     * 保证位数的随机数方法，返回值如00001字符串
     *
     * @param capacity 随机位数
     * @param bound    随机的最大值
     * @return
     */
    public static String getRandomNumber(int capacity, int bound) {
        StringBuilder capacityForm = new StringBuilder();
        capacityForm.append("%").append(capacity).append("d");
        return String.format(capacityForm.toString(), random.nextInt(bound)).replace(" ", "0");
    }
    /**
     * 最大值到0的正整数随机
     *
     * @param bound
     * @return
     */
    public static Integer getRandomNumber(int bound) {
        return random.nextInt(bound);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
//            System.out.println(getRandomNumber(5, 99999));
            System.out.println(getRandomNumber(99999));
        }
    }

}
